package com.twt.survey.common;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

@Data
public class BaseResponse<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = -7690374215567420449L;
    /**
     * 状态码
     */
    private int code;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 状态码描述
     */
    private String msg;

    /**
     * 详细信息
     */
    private String description;

    public BaseResponse() {
    }

    public BaseResponse(int code, T data, String msg, String description) {
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.description = description;
    }

    public BaseResponse(T data, ErrorCode errorCode) {
        this(errorCode.getCode(), data, errorCode.getMsg(), errorCode.getDescription());
    }

    public BaseResponse(ErrorCode errorCode, String description) {
        this(errorCode.getCode(), null, errorCode.getMsg(), description);
    }
}
